#include<iostream>
#include<cmath>
using namespace std;
const int N = 55;
int a[N], b[N];
int n;
int main()
{
	cin >> n;
	int sum1 = 0;
	int sum2 = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		sum1 += a[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> b[i];
		sum2 += b[i];
	}
	if (sum1 != sum2) {
		cout << -1 << endl;
		return 0;
	}
	int ans = 0;
	/*for (int i = 1; i <= n; i++) {
		if (a[i] == b[i]) {
			continue;
		}
		else if (a[i] < b[i]) {
			int k = i + 1;
			while (a[i] != b[i]) {
				bool flag = 0;
				while (a[k] && k <= n) {
					ans += k - i;
					a[k]--;
					a[i]++;
					if (a[i] == b[i]) {
						flag = 1;
						break;
					}
				}
				if (flag) {
					break;
				}
				else {
					k++;
				}
			}
		}
		else {
			while (a[i] != b[i]) {
				a[i]--;
				a[i + 1]++;
				ans++;
			}
		}
	}*/
	for (int i = 1; i < n; i++) {
		int k = a[i] - b[i];
		a[i + 1] += k;
		ans += abs(k);
	}
	cout << ans << endl;
	return 0;
}